import os

from cli.qrdecodecli import qrdecode

path = '../images'


def get_filelist(dir):
    Filelist = []

    for home, dirs, files in os.walk(path):

        for filename in files:
            # 文件名列表，包含完整路径

            Filelist.append(os.path.join(home, filename))

            # # 文件名列表，只包含文件名

            # Filelist.append( filename)

    return Filelist


if __name__ == '__main__':

    listImg = []
    listErrImg = []
    flieList = get_filelist(path)
    imgList = []
    for file in flieList:
        if file.lower().endswith('png') or file.lower().endswith('jpg'):
            imgList.append(file)
            try:
                r = qrdecode(file)
                print(r)
                if r is None:
                    listErrImg.append(r)
                elif r.endswith('failed'):
                    listErrImg.append(r)
                elif r not in listImg:
                    listImg.append(r)
                else:
                    print('重复元素')
            except:
                listErrImg.append('err')
                pass

    print('总计：%d,重复：%d,错误：%d' % (len(imgList), len(imgList) - len(listImg) - len(listErrImg), len(listErrImg)))
    os.system("pause")
